package com.test.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "user")
public class UserController {

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public ModelAndView login(HttpServletRequest request) {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		HttpSession session = request.getSession();
		ModelAndView view = new ModelAndView();
		if (true) { // 验证用户的方法写在service层
			session.setAttribute("username", username);
			// 返回的视图名称,/WEB-INF/jsp/welcome.jsp
			view.setViewName("welcome");
			view.addObject("username", username);// 添加数据模型
		}
		return view;
	}
}
